package com.platform.common.config.shiro;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

/**
 * Shiro Session监听器
 * 
 * @author LiangMingHui
 *
 */
public class ShiroSessionListener implements SessionListener {

	private static final Logger logger = LoggerFactory.getLogger(ShiroSessionListener.class);

	@Resource
	private ShiroSessionDAO sessionDao;

	@Override
	public void onStart(final Session session) {
		this.sessionDao.create(session);
		logger.info("session {} onStart", session.getId());
	}

	@Override
	public void onStop(final Session session) {
		this.sessionDao.delete(session);
		logger.debug("session {} onStop", session.getId());
	}

	@Override
	public void onExpiration(final Session session) {
		this.sessionDao.delete(session);
		logger.debug("session {} onExpiration", session.getId());
	}
}